package cn.edu.tju.elm.repository;

import cn.edu.tju.elm.model.Business;
import cn.edu.tju.elm.model.Food;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.math.BigDecimal;
import java.util.List;

/**
 * ClassName: FoodRepository
 * Package: cn.edu.tju.elm.repository
 * Description:
 *
 * @Author Niu Wenhang
 * @Create 2025/9/17 21:39
 * @Version 1.0
 */
public interface FoodRepository extends JpaRepository<Food, Long> {
    @Query("SELECT f.business.id FROM Food f WHERE f.id = :foodId")
    public Long findBusinessId(@Param("foodId") Long id);

    @Query("SELECT f.business FROM Food f WHERE f.id = :foodId")
    public Business findBusiness(@Param("foodId") Long id);

    @Query("SELECT f.foodPrice FROM Food f WHERE f.id = :foodId")
    public BigDecimal findFoodPrice(@Param("foodId") Long id);

    public List<Food> findByDeletedFalse();
    public List<Food> findByBusinessIdAndDeletedFalse(Long businessId);
    
    // 根据商品名称模糊查询
    public List<Food> findByFoodNameContainingAndDeletedFalse(String name);
    
    // 根据价格范围查询
    public List<Food> findByFoodPriceBetweenAndDeletedFalse(BigDecimal minPrice, BigDecimal maxPrice);
    
    // 查询在售商品
    public List<Food> findByOnSaleTrueAndDeletedFalse();
    public List<Food> findByOnSaleTrueAndBusinessIdAndDeletedFalse(Long businessId);
}
